package edu.sias.hyzn.controller;

import edu.sias.common.core.controller.BaseController;
import edu.sias.common.core.domain.AjaxResult;
import edu.sias.hyzn.domain.Visit;
import edu.sias.hyzn.service.impl.VisitService;
import edu.sias.hyzn.vo.BindRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/hyzn/visit")
@Slf4j
public class VisitController extends BaseController {

    private final VisitService visitService;

    @Autowired
    public VisitController(VisitService visitService) {
        this.visitService = visitService;
    }

    @PutMapping("/bind-patient")
    public AjaxResult bindPatient(@RequestBody BindRequest bindRequest){
        return toAjax(visitService.bindPatient(bindRequest.getPatientId(), bindRequest.getVisitIds()));
    }

    @PutMapping("/misdiagnose")
    public AjaxResult misdiagnose(@RequestBody Visit visit){
        log.debug("misdiagnose: {}", visit);
        if (visit.getId() == null){
            return AjaxResult.error(400, "请传入要修改的id");
        }
        if (visit.getStatus() == null){
            return AjaxResult.error(400, "请传入要修改的状态");
        }
        return toAjax(visitService.misdiagnose(visit));
    }
}
